package cn.toma.controller.others;

import cn.toma.common.exception.FfBootException;
import cn.toma.common.utils.web.HttpUtil;
import cn.toma.common.vo.FfBootConstant;
import cn.toma.config.web.utli.FfBootResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

@Slf4j
@Validated
@RestController
@RequestMapping("weather")
public class WeatherController
{

	@GetMapping
	@RequiresPermissions("weather:view")
	public FfBootResponse queryWeather(@NotBlank(message = "{required}") String areaId) throws FfBootException
	{
		try {
			String data = HttpUtil.sendPost(FfBootConstant.MEIZU_WEATHER_URL, "cityIds=" + areaId);
			return new FfBootResponse().data(data);
		} catch (Exception e) {
			String message = "天气查询失败";
			log.error(message, e);
			throw new FfBootException(message);
		}
	}
}
